

<html>
  <head>
    <%= javascript_include_tag :defaults %>
    <%= calendar_date_select_includes "red" %>


    <script type='text/javascript'>
      function hide_re(val){
        if(val.checked){
<%#*document.getElementById("div_repeat1").style.visibility = 'visible';%>
<%#*document.getElementById("div_repeat2").style.visibility = 'visible';%>
    }
    else
    {
<%#*document.getElementById("div_repeat1").style.visibility = 'hidden';%>
<%#*document.getElementById("div_repeat2").style.visibility = 'hidden';%>
    }

  };

  function set_text(value){
      if(value=="1"){
        document.getElementById("div_s_text").innerHTML = "";
      }else{
        document.getElementById("div_s_text").innerHTML = "s";
      }

   };


  function repeats_select(value){
    document.getElementById("div_repeat_weekly").style.display = 'none';
    document.getElementById("div_repeat1").style.display = '';
    document.getElementById("div_repeat_monthly").style.display = '';
    document.getElementById("div_text").style.display = '';

    switch(value)
    {
      case "No Repeats":
        document.getElementById("div_text").style.display = 'none';
        document.getElementById("div_repeat_monthly").style.display = 'none';
        document.getElementById("div_repeat1").style.display = 'none';
        break;
      case "Daily":
        document.getElementById("div_repeat_weekly").style.display = 'none';
        document.getElementById("div_text").innerHTML = "day";
        break;
      case "Weekly":
        document.getElementById("div_text").innerHTML = "week";
        document.getElementById("div_repeat_weekly").style.display = '';
        break;
      case "Monthly":
        document.getElementById("div_text").innerHTML = "month";
<%#*document.getElementById("div_repeat_weekly").style.visibility = 'visible';%>
        break;
      case "Yearly":
        document.getElementById("div_text").innerHTML = "year";
<%#*document.getElementById("div_repeat_weekly").style.visibility = 'visible';%>
        break;
      default:
<%#*document.getElementById("div_repeat_weekly").style.visibility = 'visible';%>
      }

    };


    </script>
    <script src="/javascripts/events_calendar_js/calendar_validation.js"></script>
  </head>

  <body>
   
    <%
    mon_value,tue_value,wen_value,thu_value,fri_value,sat_value,sun_value=false
    
    if not @rrule.nil?
      repeat_value= @rrule["FREQ"].titleize
      until_value=Date.parse(@rrule["UNTIL"])
      interval_value=@rrule["INTERVAL"]
      start_value=Time.parse(@rrule["DTSTART"])
      end_value=Time.parse(@rrule["DTEND"])
      
        array=@rrule["BYDAY"].split(',') if not @rrule["BYDAY"].nil?
      if not array.nil?
      array.each{|i|
        case i
        when "SU":
            sun_value=true
        when "MO":
          mon_value=true  
        when "TU":
          tue_value=true
        when "WE":
          wen_value=true
        when "TH":
          thu_value=true
        when "FR":
          fri_value=true
        when "SA":   
          sat_value=true
        end      
      }
      end
    else
      repeat_value= "No Repeats"
      until_value=Time.now
      interval_value="1"
      start_value=@event.start
      end_value=@event.end
    end
  %>
    <h1>Edit Event</h1>
      <div id="errorText" style="color:red"><%=if(@update_status=="false") then "Update failed !" elsif(@status=="true") then "Update Successful !" else ""  end %></div>
                                        
    <% form_tag( '/events/edit/' , {:onSubmit => 'return validateEdit();'})  do -%>
      <table cellpadding="4" border="0">
        <tr>
          <td>
            Event Type:
          </td>
          <td>
            <%if not @event.event_type.nil?
                type=@event.event_type.titleize 
            else
              type="Other"
             end
            %>
           
            <%= select_tag "event_type", options_for_select( @events_type,type) %>
          </td>
        </tr>
        <tr>
          <td>
            Title:
          </td>
          <td> 
            <%= text_field "event", "title"%>

          </td>
        </tr>
        
        <tr>
          <td>
            Where:
          </td>
          <td>
            <%= text_field "event", "where"%>
          </td>
        </tr>


        <tr>
          <td>
            Content:
          </td>
          <td>
            <%= text_field "event", "content"%>
          </td>
        </tr>
<tr>
          <td>
            Web Page:
          </td>
          <td colspan="3">

            <%= text_field "event", "webpage"%><span style="font-size:0.8em;color:#C0C0C0">(http://www.samplepage.com)</span>
          </td>
        </tr>


        <tr>

          <td>
            Start Time:
          </td>
          <td>
            <%= calendar_date_select_tag "start_date", start_value, {:size=>"24%",:time => true ,:onchange => "startDateOnchage()"}  %>
          </td>

          <td>
            End Time:
          </td>
          <td>
            <%= calendar_date_select_tag "end_date", end_value, {:size=>"24%",:time => true ,:onchange => "onChangeDate()"} %>
          </td>
        </tr>
        <tr>
          <td>
            Repeat :
          </td>
          <td>
             <%= select_tag "repeats", options_for_select(["No Repeats","Daily","Weekly","Monthly","Yearly"], repeat_value ),{:onchange => 'repeats_select(this.value)'} %>

          </td>
     
        </tr>
        <tr>
          <td colspan="4">
            <div id="div_repeat_monthly">
              <% days=[]
              (1..30).each{|i|
                days.push(i.to_s)} %>
              Repeat every:<%= select_tag "repeat_every", options_for_select( days, interval_value),{:onchange => "set_text(this.value)"} %> <span id="div_text"></span><span id="div_s_text"></span>

              <hr>
            </div>

            <div id="div_repeat_weekly">
              Repeat On:

              <%= check_box_tag "c_b_sun", true,sun_value%>Sun
              <%= check_box_tag "c_b_mon", true,mon_value%>Mon
              <%= check_box_tag "c_b_tue", true,tue_value%>Tue
              <%= check_box_tag "c_b_wen", true,wen_value%>Wen
              <%= check_box_tag "c_b_thu", true,thu_value%>Thu
              <%= check_box_tag "c_b_fri", true,fri_value%>Fri
              <%= check_box_tag "c_b_sat", true,sat_value%>Sat
              <hr>
            </div>

            <div id="div_repeat1">
              Repeat Until:
              <%= calendar_date_select_tag "repeat_until", until_value,{:time => false,:onchange => "onChangeUntil()"} %>
            <hr>
            </div>
          </td>

        </tr>
        <tr>
          <td colspan="2">

             <%if @event.highlight=="true"
               highlight_value=true
              else
                highlight_value=false
              end
             %>
            Highlight on Calendar: <%= check_box_tag "highlight", true,highlight_value%>
          </td>
        </tr>

        <tr>
          <td>
            <%= hidden_field_tag 'cal_id', @cal_id %>
            <%= hidden_field_tag 'event_title', @event_title %>
            <%= hidden_field_tag 'cal_title', @cal_title %>
            <%= hidden_field_tag 'event_id', @event_id %>
          </td>

          <td align="right">
            <br>

            <%= submit_tag 'Save' %>
          </td>
        </tr>

      </table>
    <% end -%>
    <%#= link_to 'Back', posts_path %>

    <script type='text/javascript'>
                  var repeat_type="<%=repeat_value%>";
                  var interval="<%=interval_value%>";
                  repeats_select(repeat_type);
                  set_text(interval);
    </script>
    <%=link_to 'Back to Events', "/events?title=#{@cal_title}&cal_id=#{@cal_id}" %>
  </body>

</html>














